package com.ewivt.excel.utils;

import com.alibaba.excel.EasyExcel;
import com.ewivt.excel.mapper.DistanceMapper;
import com.ewivt.excel.model.Distance;
import com.ewivt.excel.model.DistanceExcel;
import com.ewivt.excel.model.Location;
import com.ewivt.excel.model.LocationExcel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class GetFromExcel {

    public void init() {

        String locationExcelFile = "C:\\Users\\徐成超\\Desktop\\code\\节约算法\\output_test_上午且条件0.xlsx";
        String distanceExcelFile = "C:\\Users\\徐成超\\Desktop\\code\\节约算法\\标准数据集.xlsx";
        List<LocationExcel> locationExcelList = EasyExcel.read(locationExcelFile).head(LocationExcel.class).sheet("上午且条件0").doReadSync();
        List<DistanceExcel> distanceExcelList =EasyExcel.read(distanceExcelFile).head(DistanceExcel.class).sheet("表2点位距离和时间表").doReadSync();
        List<Location> locationList = new ArrayList<>();
        locationExcelList.forEach(o->{
            locationList.add(o.toLocation());
        });
        List<Distance> distanceList = new ArrayList<>();
        distanceExcelList.forEach(o->{
            distanceList.add(o.toDistance());
        });
        SingleRouteAlgorithm singleRouteAlgorithm = new SingleRouteAlgorithm();
        long timeBefore = System.currentTimeMillis();
        List<Location> result = singleRouteAlgorithm.getSingleRoute(locationList,distanceList);
        long timeAfter = System.currentTimeMillis();
        log.info("总计耗时："+(timeAfter-timeBefore)/1000+" 秒");
        log.info("计算完毕！");
        result.forEach(o->{
            log.info(o.getLocationName());
        });
    }

}
